﻿using System;
using Actors;

namespace Combat
{
    /// <summary>
    /// 战斗单位。
    /// 每个参与战斗的单位都是一个战斗单位。
    /// </summary>
    public class BattleUnit
    {
        public Character Character { get; private set; }

        #region Combat Attributes
        
        private readonly float[] m_CombatAttributes = new float[BattleAttribute.Count];

        public float Hp => GetCombatAttribute(BattleAttribute.Hp);
        public float Mp => GetCombatAttribute(BattleAttribute.Mp);
        public float Atk => GetCombatAttribute(BattleAttribute.Atk);
        public float Def => GetCombatAttribute(BattleAttribute.Def);
        public float Spd => GetCombatAttribute(BattleAttribute.Spd);
        public float Crit => GetCombatAttribute(BattleAttribute.Crit);
        public float CritDamage => GetCombatAttribute(BattleAttribute.CritDamage);
        
        
        public float GetCombatAttribute(int index)
        {
            return m_CombatAttributes[index];
        }

        private void SetCombatAttribute(int index, float value)
        {
            m_CombatAttributes[index] = value;
        }

        #endregion

        public void BindCharacter(Character character)
        {
            Character = character;
        }
        
        public void SetCombatAttributes(float[] attributes)
        {
            for (int i = 0; i < Math.Min(BattleAttribute.Count, attributes.Length); i++)
            {
                m_CombatAttributes[i] = attributes[i];
            }
        }
        
        
        public void Reset()
        {
            Character = null;
            for (int i = 0; i < BattleAttribute.Count; i++)
            {
                m_CombatAttributes[i] = 0f;
            }
        }

    }
}